package client_commands;

import java.util.StringTokenizer;

import client.ClientApplication;
import client_tree.User;

public class SERV_DELCommand extends Command {

	public SERV_DELCommand(String parameter) {
		setCode(SERV_DEL);
		setParameter(parameter);
	}
	
	
	@Override
	public boolean executeCommand(ClientApplication theApp) {
		StringTokenizer tokens = new StringTokenizer(getParameter());
		
		String username = tokens.nextToken();

		User user = theApp.getClientModel().getOnlineModel().getUserByUsername(username);;

		if (user == null) {
			user = theApp.getClientModel().getOfflineModel().getUserByUsername(username);;
		}
		
		if (user == null) {
			return false;
		}
		
		user.setStatus(OFFLINE_STATUS);
		theApp.getClientModel().addUser(user);
		
		return true;
	}
}
